package com.lhf.azkaban.springbatch.example.batchwriter;

import com.lhf.azkaban.springbatch.example.utils.DateUtil;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mybatis.spring.batch.MyBatisBatchItemWriter;
import org.springframework.batch.item.SpELItemKeyMapper;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author:95780
 * @Date: 16:27 2019/11/21
 * @Description: 测试使用MyBatisBatchItemWriter 方法
 */
//@Component
public class RepayOrderMybatisItemWrite<RepayOrderInfo> extends MyBatisBatchItemWriter {
    private static final Logger logger = LogManager.getLogger(RepayOrderMybatisItemWrite.class);
    public RepayOrderMybatisItemWrite(SqlSessionFactory sqlSessionFactory) {
        logger.info("======RepayOrderMybatisItemWrite Begin ======   time:   " + DateUtil.parseDateTime(LocalDateTime.now(), DateUtil.PATTERN_DEFAULT_DATA));
        repayOrderWrite(sqlSessionFactory);
    }

    private void repayOrderWrite(SqlSessionFactory sqlSessionFactory) {
        setSqlSessionFactory(sqlSessionFactory);
        setStatementId("com.lhf.azkaban.springbatch.example.mapper.RepayOrderInfoMapper.saveRepayOrderInfoBatch");
        setAssertUpdates(false);
    }

    @Override
    public void write(List items) {
        logger.info("======RepayOrderMybatisItemWrite====== write items " + items.size());
        logger.info("======RepayOrderMybatisItemWrite====== write items " + items);
        super.write(items);
    }
}
